FROM wangrzqi/oneapi-pure

ENV NCARG_ROOT=/opt/software/ncl/
ENV PATH=/opt/software/ncl/bin:${PATH}

COPY libgfortran.so.3 /usr/lib/x86_64-linux-gnu/
RUN mkdir -p /opt/software/ncl && cd /opt/software/ncl && \
    wget -c https://www.earthsystemgrid.org/api/v1/dataset/ncl.662_2.nodap/file/ncl_ncarg-6.6.2-Debian9.8_64bit_nodap_gnu630.tar.gz && \
    tar xf ncl_ncarg-6.6.2-Debian9.8_64bit_nodap_gnu630.tar.gz && \
    rm ncl_ncarg-6.6.2-Debian9.8_64bit_nodap_gnu630.tar.gz

RUN apt-get update && \
    apt-get install -y git libpng-dev libncurses-dev ruby sqlite3 libxrender1 libfontconfig1 libproj-dev proj-data proj-bin libgeos-dev && \
    apt-get install -y netcat net-tools iproute2 rsync lftp flex byacc && \
    sed -i 's/#   StrictHostKeyChecking ask/    StrictHostKeyChecking no/' /etc/ssh/ssh_config && \
    sed -i 's/    SendEnv LANG LC_*/#   SendEnv LANG LC_*/' /etc/ssh/ssh_config && \
    rm -rf /var/lib/apt/lists/*

RUN ["/bin/bash", "-c", "cd /opt/software && \
    git clone https://gitee.com/wangrzqi/starman && \
    . /opt/software/starman/setup/bashrc && \
    starman setup --install-root /opt/software --cache-root /tmp/starman --rc-root /var/starman && \
    starman config -c ifort --cc $(which icc) --mpicc $(which mpiicc) \
                   --cxx $(which icpc) --mpicxx $(which mpiicpc) \
                   --fc $(which ifort) --mpifc $(which mpiifort) && \
    starman config -c ifort && \
    starman install netcdf eccodes bufrlib lapack fox -j 4 -k && \
    starman install met -j 4 -k && \
    rm -rf /tmp/starman/*"]

RUN ["/bin/bash", "-c", "apt-get update && \
    apt-get install -y python3 python3-pip && \
    . /opt/software/starman/setup/bashrc && \
    . /opt/intel/oneapi/setvars.sh && \
    starman load netcdf eccodes && \
    pip3 install numpy scipy matplotlib pyproj pygrib \
                 xarray pendulum pexpect f90nml psutil \
                 psycopg2-binary netCDF4 requests jinja2 \
                 packaging cartopy proplot cmaps && \
    pip3 install wrf-python && \
    pip3 install flask-appbuilder && \
    pip3 install apache-airflow[crypto,celery,postgres,redis] && \
    rm -rf /var/lib/apt/lists/* && rm -rf ~/.cache/pip"]

RUN echo "root:123456" | chpasswd

ENV AIRFLOW_USER airflow
ENV AIRFLOW_HOME /home/airflow
RUN useradd -s /bin/bash -m -d ${AIRFLOW_HOME} ${AIRFLOW_USER}

RUN chown -R airflow.airflow /opt
USER $AIRFLOW_USER
WORKDIR $AIRFLOW_HOME

COPY bash.bashrc /etc/bash.bashrc
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
